package com.wpi.smarttour;
import com.wpi.smarttour.helpers.Utilities;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

/*
 * Activity to show video to user
 */
public class SmartViewer extends Activity
{
   // SERVER IP AT UTILITIES CLASS
   // public static String SERVER_IP = "http://10.100.147.195/";
   private static String PATH_TO_FILE = "/ST/uploads/";
   VideoView videoView;

   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.viewing);
      Utilities.LogDebug("SmartView", "SmartView has started");
      Utilities.LogDebug("SmartView", "Path::" + Utilities.IP_ADDRESS + PATH_TO_FILE + MapActivity.FILE_NAME_FOR_PLAYBACK);
      // Start Video Button
      final Button videoButton = (Button) findViewById(R.id.videoButton);
      videoButton.setOnClickListener(new View.OnClickListener()
      {
         public void onClick(View v)
         {
            Utilities.LogDebug("Video Button clicked");
            playBack();
         }
      });
   }

   // Start Video
   public void playBack()
   {
      try
      {
         Utilities.LogDebug("SmartView", "Starting play back");
         Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(Utilities.IP_ADDRESS + PATH_TO_FILE + MapActivity.FILE_NAME_FOR_PLAYBACK));
         startActivity(browserIntent);
      }
      catch (IllegalArgumentException e)
      {
         // TODO Auto-generated catch block
         Utilities.LogError("Video Playback", e);
      }
      catch (IllegalStateException e)
      {
         // TODO Auto-generated catch block
         Utilities.LogError("Video Playback", e);
      }
   }
}
